package org.langqiao.thread;

public class NumberThread extends Thread{
	private int first;//序列初值
	public NumberThread(String name,int first)
	{
		super(name);
		this.first=first;
	}
	public NumberThread(String name)
	{
		this(name,0);
	}
	public void run()//复写Thread的run方法
	{
		synchronized(this) {
			System.out.print("\n"+this.getName()+":");
			for(int i=first;i<=50;i+=2)
				System.out.print(i+" ");
				System.out.println(this.getName()+"结束！");
		};
		
	}
	public static void main(String[] args)
	{
		System.out.println("目前的线程="+Thread.currentThread().getName());//输出当前线程对象
		NumberThread Thread_odd=new NumberThread("奇数线程",1);//奇数线程
		Thread_odd.setPriority(5);
		NumberThread Thread_even=new NumberThread("偶数线程",2);//偶数线程
		Thread_odd.start();//奇数线程开始
		Thread_even.start();//偶数线程开始
		Thread_even.setPriority(10);
		System.out.println("活跃的线程="+Thread_even.activeCount());//输出当前活动的线程数
	}
}
